package com.ynny.dao;

import com.ynny.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository(value = "studentDao")
public class StudentDaoImp implements StudentDao{

    //JdbcTemplate
    //操作哪个数据
    //传统创建
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Override
    public int insertStudent() {
        String sql = "insert into student (name,age) values (?,?)";
        int i = jdbcTemplate.update(sql, "张三", 20);

        return i;
    }

    @Override
    public List<Student> selectAllStudents() {

        String sql = "select * from student";
        List<Student> list = jdbcTemplate
                .query(sql,
                        new BeanPropertyRowMapper<>(Student.class));

        return list;
    }
}
